using Bean.Infrastructure.Extensions;
using Bean.PolicyBackend.Handler;
using Bean.Quartz.Core;

namespace Bean.PolicyBackend;

internal class Program
{
    private static void Main(string[] args)
    {
        var builder = WebApplication.CreateBuilder(args);
        builder.AddSqlSugar().AddAutofac().AddRedisConfig().AddLogging("Nlog.config").AddAutoMap();


        builder.Services.AddQuartz();
        builder.Services.AddHttpClient();
        
        builder.Services.AddHostedService<PolicyRuleUpdatePlanHandler>();
        
        builder.Services.AddSingleton<TestJob>();


        // builder.Services.AddSingleton<TestSubscribe>();
        //
        //
        var app = builder.Build();
        //
        // var _testSubscribe = app.Services.GetService<TestSubscribe>();
        //
        // app.Lifetime.ApplicationStarted.Register(() => { _testSubscribe?.Start(); });
        //
        // app.Lifetime.ApplicationStopped.Register(() => { _testSubscribe?.Stop(); });
        
        app.UseQuartz(async startup =>
        {
            await startup.AddTimerJob<TestJob>("Test", JobIntervalType.Seconds, 2);
        });


        app.Run();
    }
}
